package com.jubaozan.service.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jubaozan.c3.framework.constants.Constants;
import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.dao.youme.domain.StoreUserAudit;
import com.jubaozan.service.platform.decorator.TeamAuditDecorator;
import com.jubaozan.service.platform.vo.StoreUserAuditVO;
import com.jubaozan.service.platform.vo.TeamUserProgressVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName TeamRegisterController
 * @Description 团长审核相关接口Controller
 * @Author SunWei
 * @Version 1.0
 **/
@Api(tags = {"团长审核相关接口"}, value = "团长审核相关接口")
@RestController
@RequestMapping("/team/audit")
@Validated
public class TeamAuditController {

    private final TeamAuditDecorator teamAuditDecorator;

    public TeamAuditController(TeamAuditDecorator teamAuditDecorator) {
        this.teamAuditDecorator = teamAuditDecorator;
    }

    @ApiOperation(value = "团长审核列表")
    @GetMapping("")
    public ResultHolder<List<StoreUserAuditVO>> queryTeamList(@RequestHeader(Constants.KEY_C3_STOREID) Long storeId,
                                                              @ApiParam(value = "审核状态") @RequestParam("status")List<Integer> status,
                                                              @ApiParam(value = "等级") @RequestParam(required = false,value="levelId")Integer levelId,
                                                              @ApiParam(value = "页码")@RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                              @ApiParam(value = "每页显示条数")@RequestParam(required = false, defaultValue = "10") Integer pageSize){
        return ResultHolder.success(teamAuditDecorator.queryTeamList(storeId,status,levelId,pageNo,pageSize));
    }

    @ApiOperation(value = "团长审核通过")
    @PutMapping("/pass")
    public ResultHolder<Object> pass(@RequestHeader(Constants.KEY_C3_STOREID) Long storeId,
                                     @ApiParam(value = "用户id") @RequestParam("userId") Long userId,
                                     @ApiParam(value = "目标等级",example = "2") @RequestParam("targetLevel")  Integer targetLevel){
        return ResultHolder.success(teamAuditDecorator.pass(storeId,userId,targetLevel));
    }

    @ApiOperation(value = "团长审核拒绝")
    @PutMapping("/refuse")
    public ResultHolder<Object> refuse(@RequestHeader(Constants.KEY_C3_STOREID) Long storeId,
                                       @ApiParam(value = "用户id") @RequestParam("userId") Long userId,
                                       @ApiParam(value = "拒绝原因") @RequestParam("rejectReason")  String rejectReason){
        return ResultHolder.success(teamAuditDecorator.refuse(storeId,userId,rejectReason));
    }

    @ApiOperation(value = "查询团长审核进度")
    @GetMapping("/progress")
    public ResultHolder<TeamUserProgressVO> queryProgress(@RequestHeader(Constants.KEY_X_C3_AGENTID) Long userId,
                                                          @RequestHeader(Constants.KEY_C3_STOREID) Long storeId){
        return ResultHolder.success(teamAuditDecorator.queryProgress(storeId,userId));
    }
}
